{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "36c0d2d5",
   "metadata": {},
   "source": [
    "## 1. APP U本位合约交易账户函数总览"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80cb6c0d",
   "metadata": {},
   "source": [
    "|方法|解释|\n",
    "|:---|:---|\n",
    "|get_account|获取账户信息|\n",
    "|get_balance|获取单个产品余额|\n",
    "|get_balances|获取全部产品余额（列表格式）|\n",
    "|get_balancesMap|获取全部产品余额（字典格式）|\n",
    "|set_leverage|调整开仓杠杆|\n",
    "|set_marginType|更改持仓模式|\n",
    "|get_position|获取单个产品的持仓信息|\n",
    "|get_positions|获取全部产品的持仓信息（列表格式）|\n",
    "|get_positionsMap|获取全部产品的持仓信息字典（字典格式）|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01f5be7e",
   "metadata": {},
   "source": [
    "## 2. 模型实例化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9429b240",
   "metadata": {},
   "outputs": [],
   "source": [
    "from binance_interface.app import BinanceUM\n",
    "from binance_interface.app.utils import eprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "25c41f5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转发：需搭建转发服务器，可参考：https://github.com/pyted/binance_resender\n",
    "proxy_host = None\n",
    "key = 'xxxx'\n",
    "secret = 'xxxx'\n",
    "\n",
    "binanceUM = BinanceUM(\n",
    "    key=key, secret=secret,\n",
    "    proxy_host=proxy_host\n",
    ")\n",
    "account = binanceUM.account"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8683c7d0",
   "metadata": {},
   "source": [
    "## 3. 获取账户信息 get_account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "782b8436",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'feeTier': 0,\n",
      "          'canTrade': True,\n",
      "          'canDeposit': True,\n",
      "          'canWithdraw': True,\n",
      "          'tradeGroupId': -1,\n",
      "          'updateTime': 0,\n",
      "          'multiAssetsMargin': False,\n",
      "          'totalInitialMargin': '74.07260000',\n",
      "          'totalMaintMargin': '0.21261825',\n",
      "          'totalWalletBalance': '100.09787528',\n",
      "          'totalUnrealizedProfit': '-1.35838677',\n",
      "          'totalMarginBalance': '98.73948851',\n",
      "          'totalPositionInitialMargin': '38.17260000',\n",
      "          'totalOpenOrderInitialMargin': '35.90000000',\n",
      "          'totalCrossWalletBalance': '60.58480282',\n",
      "          'totalCrossUnPnl': '0.00000000',\n",
      "          'availableBalance': '24.68480282',\n",
      "          'maxWithdrawAmount': '24.68480282',\n",
      "          'assets': [{'asset': 'BTC',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     {'asset': 'XRP',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     {'asset': 'TUSD',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     {'asset': 'BNB',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     {'asset': 'ETH',\n",
      "                      'walletBalance': '0.00000000',\n",
      "                      'unrealizedProfit': '0.00000000',\n",
      "                      'marginBalance': '0.00000000',\n",
      "                      'maintMargin': '0.00000000',\n",
      "                      '...': '......'},\n",
      "                     '......'],\n",
      "          'positions': [{'symbol': 'SNTUSDT',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        {'symbol': 'SNTUSDT',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        {'symbol': 'SUSHIUSDT',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        {'symbol': 'SUSHIUSDT',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        {'symbol': 'BTSUSDT',\n",
      "                         'initialMargin': '0',\n",
      "                         'maintMargin': '0',\n",
      "                         'unrealizedProfit': '0.00000000',\n",
      "                         'positionInitialMargin': '0',\n",
      "                         '...': '......'},\n",
      "                        '......']},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "account_result = account.get_account()\n",
    "eprint(account_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "609dc9ca",
   "metadata": {},
   "source": [
    "## 4. 获取单个产品余额 get_balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4aeabe24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "          'asset': 'BTC',\n",
      "          'balance': '0.00000000',\n",
      "          'crossWalletBalance': '0.00000000',\n",
      "          'crossUnPnl': '0.00000000',\n",
      "          'availableBalance': '0.00000000',\n",
      "          'maxWithdrawAmount': '0.00000000',\n",
      "          'marginAvailable': True,\n",
      "          'updateTime': 0},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 等价于下面代码：account.get_balance(symbol='BTCUSDT',base_asset='USDT')\n",
    "balance_result = account.get_balance(asset='BTC')\n",
    "eprint(balance_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f343866e",
   "metadata": {},
   "source": [
    "## 5. 获取全部产品余额（列表格式） get_balances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2adddd19",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': [{'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'BTC',\n",
      "           'balance': '0.00000000',\n",
      "           'crossWalletBalance': '0.00000000',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'XRP',\n",
      "           'balance': '0.00000000',\n",
      "           'crossWalletBalance': '0.00000000',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'TUSD',\n",
      "           'balance': '0.00000000',\n",
      "           'crossWalletBalance': '0.00000000',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'BNB',\n",
      "           'balance': '0.00000000',\n",
      "           'crossWalletBalance': '0.00000000',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'ETH',\n",
      "           'balance': '0.00000000',\n",
      "           'crossWalletBalance': '0.00000000',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'USDT',\n",
      "           'balance': '100.09787528',\n",
      "           'crossWalletBalance': '60.58480282',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'USDP',\n",
      "           'balance': '0.00000000',\n",
      "           'crossWalletBalance': '0.00000000',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'USDC',\n",
      "           'balance': '0.00000000',\n",
      "           'crossWalletBalance': '0.00000000',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'}],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数assets默认为[]，表示全部货币\n",
    "balances_result = account.get_balances()\n",
    "eprint(balances_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9e7f27c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': [{'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'BTC',\n",
      "           'balance': '0.00000000',\n",
      "           'crossWalletBalance': '0.00000000',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'},\n",
      "          {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "           'asset': 'ETH',\n",
      "           'balance': '0.00000000',\n",
      "           'crossWalletBalance': '0.00000000',\n",
      "           'crossUnPnl': '0.00000000',\n",
      "           '...': '......'}],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个货币\n",
    "balances_result = account.get_balances(assets=['BTC', 'ETH'])\n",
    "eprint(balances_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "517f3aec",
   "metadata": {},
   "source": [
    "## 6. 获取全部产品余额（字典格式）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "91382d02",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'BTC': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                  'asset': 'BTC',\n",
      "                  'balance': '0.00000000',\n",
      "                  'crossWalletBalance': '0.00000000',\n",
      "                  'crossUnPnl': '0.00000000',\n",
      "                  '...': '......'},\n",
      "          'XRP': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                  'asset': 'XRP',\n",
      "                  'balance': '0.00000000',\n",
      "                  'crossWalletBalance': '0.00000000',\n",
      "                  'crossUnPnl': '0.00000000',\n",
      "                  '...': '......'},\n",
      "          'TUSD': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                   'asset': 'TUSD',\n",
      "                   'balance': '0.00000000',\n",
      "                   'crossWalletBalance': '0.00000000',\n",
      "                   'crossUnPnl': '0.00000000',\n",
      "                   '...': '......'},\n",
      "          'BNB': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                  'asset': 'BNB',\n",
      "                  'balance': '0.00000000',\n",
      "                  'crossWalletBalance': '0.00000000',\n",
      "                  'crossUnPnl': '0.00000000',\n",
      "                  '...': '......'},\n",
      "          'ETH': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                  'asset': 'ETH',\n",
      "                  'balance': '0.00000000',\n",
      "                  'crossWalletBalance': '0.00000000',\n",
      "                  'crossUnPnl': '0.00000000',\n",
      "                  '...': '......'},\n",
      "          'USDT': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                   'asset': 'USDT',\n",
      "                   'balance': '100.09787528',\n",
      "                   'crossWalletBalance': '60.58480282',\n",
      "                   'crossUnPnl': '0.00000000',\n",
      "                   '...': '......'},\n",
      "          'USDP': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                   'asset': 'USDP',\n",
      "                   'balance': '0.00000000',\n",
      "                   'crossWalletBalance': '0.00000000',\n",
      "                   'crossUnPnl': '0.00000000',\n",
      "                   '...': '......'},\n",
      "          'USDC': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                   'asset': 'USDC',\n",
      "                   'balance': '0.00000000',\n",
      "                   'crossWalletBalance': '0.00000000',\n",
      "                   'crossUnPnl': '0.00000000',\n",
      "                   '...': '......'}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数assets默认为[]，表示全部货币\n",
    "balancesMap_result = account.get_balancesMap()\n",
    "eprint(balancesMap_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "afe6031b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'BTC': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                  'asset': 'BTC',\n",
      "                  'balance': '0.00000000',\n",
      "                  'crossWalletBalance': '0.00000000',\n",
      "                  'crossUnPnl': '0.00000000',\n",
      "                  '...': '......'},\n",
      "          'ETH': {'accountAlias': 'SguXuXmYSgTiSgfW',\n",
      "                  'asset': 'ETH',\n",
      "                  'balance': '0.00000000',\n",
      "                  'crossWalletBalance': '0.00000000',\n",
      "                  'crossUnPnl': '0.00000000',\n",
      "                  '...': '......'}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个货币\n",
    "balancesMap_result = account.get_balancesMap(assets=['BTC', 'ETH'])\n",
    "eprint(balancesMap_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "487c7aa7",
   "metadata": {},
   "source": [
    "## 7. 调整开仓杠杆 set_leverage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b75bf7ad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200, 'data': {'symbol': 'BTCUSDT', 'leverage': 2, 'maxNotionalValue': '800000000'}, 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "leverage_result = account.set_leverage(symbol='BTCUSDT', leverage=2)\n",
    "eprint(leverage_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12b058a9",
   "metadata": {},
   "source": [
    "## 8. 更改持仓模式 set_marginType"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e4b373a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200, 'msg': 'success'}\n"
     ]
    }
   ],
   "source": [
    "marginType_result = account.set_marginType(symbol='BTCUSDT', marginType='CROSSED')\n",
    "eprint(marginType_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8395e061",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200, 'msg': 'success'}\n"
     ]
    }
   ],
   "source": [
    "marginType_result = account.set_marginType(symbol='BTCUSDT', marginType='ISOLATED')\n",
    "eprint(marginType_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6c1b38f",
   "metadata": {},
   "source": [
    "## 9. 获取单个产品的持仓信息 get_position"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1cfc82a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': {}, 'SHORT': {}},\n",
      "          'ISOLATED': {'LONG': {'symbol': 'MANAUSDT',\n",
      "                                'initialMargin': '40.50029305',\n",
      "                                'maintMargin': '0.09425190',\n",
      "                                'unrealizedProfit': '-1.37959371',\n",
      "                                'positionInitialMargin': '14.50029306',\n",
      "                                'openOrderInitialMargin': '25.99999999',\n",
      "                                'leverage': '1',\n",
      "                                'isolated': True,\n",
      "                                'entryPrice': '0.4812086956521',\n",
      "                                'breakEvenPrice': '0.4771861363636',\n",
      "                                'maxNotional': '1.0E7',\n",
      "                                'positionSide': 'LONG',\n",
      "                                'positionAmt': '33',\n",
      "                                'notional': '14.50029306',\n",
      "                                'isolatedWallet': '15.86670268',\n",
      "                                'updateTime': 1706112001852,\n",
      "                                'bidNotional': '26',\n",
      "                                'askNotional': '5.34800000'},\n",
      "                       'SHORT': {}}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "position_result = account.get_position(symbol='MANAUSDT')\n",
    "eprint(position_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1782a386",
   "metadata": {},
   "source": [
    "## 10. 获取全部产品的持仓信息（列表格式） get_positions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "248774e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': [], 'SHORT': []},\n",
      "          'ISOLATED': {'LONG': [{'symbol': 'BNBUSDT',\n",
      "                                 'initialMargin': '11.74520151',\n",
      "                                 'maintMargin': '0.05872600',\n",
      "                                 'unrealizedProfit': '0.02160151',\n",
      "                                 'positionInitialMargin': '11.74520151',\n",
      "                                 'openOrderInitialMargin': '0',\n",
      "                                 'leverage': '1',\n",
      "                                 'isolated': True,\n",
      "                                 'entryPrice': '293.09',\n",
      "                                 'breakEvenPrice': '293.148618',\n",
      "                                 'maxNotional': '5.0E7',\n",
      "                                 'positionSide': 'LONG',\n",
      "                                 'positionAmt': '0.04',\n",
      "                                 'notional': '11.74520151',\n",
      "                                 'isolatedWallet': '11.72125528',\n",
      "                                 'updateTime': 1706117890515,\n",
      "                                 'bidNotional': '0',\n",
      "                                 'askNotional': '0'},\n",
      "                                {'symbol': 'MANAUSDT',\n",
      "                                 'initialMargin': '40.50020000',\n",
      "                                 'maintMargin': '0.09425130',\n",
      "                                 'unrealizedProfit': '-1.37968677',\n",
      "                                 'positionInitialMargin': '14.50020000',\n",
      "                                 'openOrderInitialMargin': '26',\n",
      "                                 'leverage': '1',\n",
      "                                 'isolated': True,\n",
      "                                 'entryPrice': '0.4812086956521',\n",
      "                                 'breakEvenPrice': '0.4771861363636',\n",
      "                                 'maxNotional': '1.0E7',\n",
      "                                 'positionSide': 'LONG',\n",
      "                                 'positionAmt': '33',\n",
      "                                 'notional': '14.50020000',\n",
      "                                 'isolatedWallet': '15.86670268',\n",
      "                                 'updateTime': 1706112001852,\n",
      "                                 'bidNotional': '26',\n",
      "                                 'askNotional': '5.34800000'},\n",
      "                                {'symbol': 'ADAUSDT',\n",
      "                                 'initialMargin': '11.92500000',\n",
      "                                 'maintMargin': '0.05962500',\n",
      "                                 'unrealizedProfit': '-0.00250000',\n",
      "                                 'positionInitialMargin': '11.92500000',\n",
      "                                 'openOrderInitialMargin': '0',\n",
      "                                 'leverage': '1',\n",
      "                                 'isolated': True,\n",
      "                                 'entryPrice': '0.4771',\n",
      "                                 'breakEvenPrice': '0.47719542',\n",
      "                                 'maxNotional': '5.0E7',\n",
      "                                 'positionSide': 'LONG',\n",
      "                                 'positionAmt': '25',\n",
      "                                 'notional': '11.92500000',\n",
      "                                 'isolatedWallet': '11.92511450',\n",
      "                                 'updateTime': 1706118204364,\n",
      "                                 'bidNotional': '0',\n",
      "                                 'askNotional': '0'}],\n",
      "                       'SHORT': []}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数symbols默认为[]，表示全部产品\n",
    "positions_result = account.get_positions()\n",
    "eprint(positions_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3beaacb6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': [], 'SHORT': []},\n",
      "          'ISOLATED': {'LONG': [{'symbol': 'BNBUSDT',\n",
      "                                 'initialMargin': '11.74275896',\n",
      "                                 'maintMargin': '0.05871379',\n",
      "                                 'unrealizedProfit': '0.01915896',\n",
      "                                 'positionInitialMargin': '11.74275896',\n",
      "                                 'openOrderInitialMargin': '0',\n",
      "                                 'leverage': '1',\n",
      "                                 'isolated': True,\n",
      "                                 'entryPrice': '293.09',\n",
      "                                 'breakEvenPrice': '293.148618',\n",
      "                                 'maxNotional': '5.0E7',\n",
      "                                 'positionSide': 'LONG',\n",
      "                                 'positionAmt': '0.04',\n",
      "                                 'notional': '11.74275896',\n",
      "                                 'isolatedWallet': '11.72125528',\n",
      "                                 'updateTime': 1706117890515,\n",
      "                                 'bidNotional': '0',\n",
      "                                 'askNotional': '0'},\n",
      "                                {'symbol': 'MANAUSDT',\n",
      "                                 'initialMargin': '40.50191963',\n",
      "                                 'maintMargin': '0.09426247',\n",
      "                                 'unrealizedProfit': '-1.37796714',\n",
      "                                 'positionInitialMargin': '14.50191963',\n",
      "                                 'openOrderInitialMargin': '26',\n",
      "                                 'leverage': '1',\n",
      "                                 'isolated': True,\n",
      "                                 'entryPrice': '0.4812086956521',\n",
      "                                 'breakEvenPrice': '0.4771861363636',\n",
      "                                 'maxNotional': '1.0E7',\n",
      "                                 'positionSide': 'LONG',\n",
      "                                 'positionAmt': '33',\n",
      "                                 'notional': '14.50191963',\n",
      "                                 'isolatedWallet': '15.86670268',\n",
      "                                 'updateTime': 1706112001852,\n",
      "                                 'bidNotional': '26',\n",
      "                                 'askNotional': '5.34800000'}],\n",
      "                       'SHORT': []}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个产品\n",
    "positions_result = account.get_positions(symbols=['MANAUSDT', 'BNBUSDT'])\n",
    "eprint(positions_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc5ced8b",
   "metadata": {},
   "source": [
    "## 11. 获取全部产品的持仓信息（字典格式） get_positionsMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3f711592",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': {}, 'SHORT': {}},\n",
      "          'ISOLATED': {'LONG': {'BNBUSDT': {'symbol': 'BNBUSDT',\n",
      "                                            'initialMargin': '11.74000000',\n",
      "                                            'maintMargin': '0.05870000',\n",
      "                                            'unrealizedProfit': '0.01640000',\n",
      "                                            'positionInitialMargin': '11.74000000',\n",
      "                                            'openOrderInitialMargin': '0',\n",
      "                                            'leverage': '1',\n",
      "                                            'isolated': True,\n",
      "                                            'entryPrice': '293.09',\n",
      "                                            'breakEvenPrice': '293.148618',\n",
      "                                            'maxNotional': '5.0E7',\n",
      "                                            'positionSide': 'LONG',\n",
      "                                            'positionAmt': '0.04',\n",
      "                                            'notional': '11.74000000',\n",
      "                                            'isolatedWallet': '11.72125528',\n",
      "                                            'updateTime': 1706117890515,\n",
      "                                            'bidNotional': '0',\n",
      "                                            'askNotional': '0'},\n",
      "                                'MANAUSDT': {'symbol': 'MANAUSDT',\n",
      "                                             'initialMargin': '40.50350000',\n",
      "                                             'maintMargin': '0.09427275',\n",
      "                                             'unrealizedProfit': '-1.37638677',\n",
      "                                             'positionInitialMargin': '14.50350000',\n",
      "                                             'openOrderInitialMargin': '26',\n",
      "                                             'leverage': '1',\n",
      "                                             'isolated': True,\n",
      "                                             'entryPrice': '0.4812086956521',\n",
      "                                             'breakEvenPrice': '0.4771861363636',\n",
      "                                             'maxNotional': '1.0E7',\n",
      "                                             'positionSide': 'LONG',\n",
      "                                             'positionAmt': '33',\n",
      "                                             'notional': '14.50350000',\n",
      "                                             'isolatedWallet': '15.86670268',\n",
      "                                             'updateTime': 1706112001852,\n",
      "                                             'bidNotional': '26',\n",
      "                                             'askNotional': '5.34800000'},\n",
      "                                'ADAUSDT': {'symbol': 'ADAUSDT',\n",
      "                                            'initialMargin': '11.92750000',\n",
      "                                            'maintMargin': '0.05963750',\n",
      "                                            'unrealizedProfit': '0.00000000',\n",
      "                                            'positionInitialMargin': '11.92750000',\n",
      "                                            'openOrderInitialMargin': '0',\n",
      "                                            'leverage': '1',\n",
      "                                            'isolated': True,\n",
      "                                            'entryPrice': '0.4771',\n",
      "                                            'breakEvenPrice': '0.47719542',\n",
      "                                            'maxNotional': '5.0E7',\n",
      "                                            'positionSide': 'LONG',\n",
      "                                            'positionAmt': '25',\n",
      "                                            'notional': '11.92750000',\n",
      "                                            'isolatedWallet': '11.92511450',\n",
      "                                            'updateTime': 1706118204364,\n",
      "                                            'bidNotional': '0',\n",
      "                                            'askNotional': '0'}},\n",
      "                       'SHORT': {}}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 参数symbols默认为[]，表示全部产品\n",
    "positionsMap_result = account.get_positionsMap()\n",
    "eprint(positionsMap_result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "14c0ae0a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'CROSSED': {'LONG': {}, 'SHORT': {}},\n",
      "          'ISOLATED': {'LONG': {'BNBUSDT': {'symbol': 'BNBUSDT',\n",
      "                                            'initialMargin': '11.74153010',\n",
      "                                            'maintMargin': '0.05870765',\n",
      "                                            'unrealizedProfit': '0.01793010',\n",
      "                                            'positionInitialMargin': '11.74153010',\n",
      "                                            'openOrderInitialMargin': '0',\n",
      "                                            'leverage': '1',\n",
      "                                            'isolated': True,\n",
      "                                            'entryPrice': '293.09',\n",
      "                                            'breakEvenPrice': '293.148618',\n",
      "                                            'maxNotional': '5.0E7',\n",
      "                                            'positionSide': 'LONG',\n",
      "                                            'positionAmt': '0.04',\n",
      "                                            'notional': '11.74153010',\n",
      "                                            'isolatedWallet': '11.72125528',\n",
      "                                            'updateTime': 1706117890515,\n",
      "                                            'bidNotional': '0',\n",
      "                                            'askNotional': '0'},\n",
      "                                'MANAUSDT': {'symbol': 'MANAUSDT',\n",
      "                                             'initialMargin': '40.50639245',\n",
      "                                             'maintMargin': '0.09429155',\n",
      "                                             'unrealizedProfit': '-1.37349432',\n",
      "                                             'positionInitialMargin': '14.50639245',\n",
      "                                             'openOrderInitialMargin': '26',\n",
      "                                             'leverage': '1',\n",
      "                                             'isolated': True,\n",
      "                                             'entryPrice': '0.4812086956521',\n",
      "                                             'breakEvenPrice': '0.4771861363636',\n",
      "                                             'maxNotional': '1.0E7',\n",
      "                                             'positionSide': 'LONG',\n",
      "                                             'positionAmt': '33',\n",
      "                                             'notional': '14.50639245',\n",
      "                                             'isolatedWallet': '15.86670268',\n",
      "                                             'updateTime': 1706112001852,\n",
      "                                             'bidNotional': '26',\n",
      "                                             'askNotional': '5.34800000'}},\n",
      "                       'SHORT': {}}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "# 指定多个产品\n",
    "positionsMap_result = account.get_positionsMap(symbols=['MANAUSDT', 'BNBUSDT'])\n",
    "eprint(positionsMap_result)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
